$(function() {
	init();
	city();
});



// 选择地区的点击事件
var bool = true;
$("body").on("click", function() {
	$("#city_1").hide();
})
$("body").on("click", ".left>div>button", function(event) {
	$("#city_1").show();

	event.stopPropagation();
});
$("body").on("click", "#city_1", function(event) {
	$("#city_1").show();
	event.stopPropagation();
})

function fristLoad() {
//	通过查询城市获取项目列表
    
    	$("#checkOut").click(function  () {
    		console.log(window.cityid);
    		$.ajax({
		type: "get",
		url: "http://192.168.59.3:8082/console/shopping/shop?shopType=1",
		contentType: "application/json",
		success: function(data) {
			console.log(data);
var data1 = JSON.parse(data);
var data2 = data1.data;
console.log(data2[0]);
			$("#table-fundManage1").bootstrapTable({
				data: data2[0],

			})
		},
		error: function(err) {
			console.log(err);
		}
	});
    	});
    	

	

}

function init() {
	$.ajax({
		type: "get",
		url: "http://192.168.59.3:8082/console/shopping/shop?shopType=1",
		contentType: "application/json",
		success: function(data) {
			console.log(data);
var data1 = JSON.parse(data);
var data2 = resHandler(data1);

    
			$("#table-fundManage1").bootstrapTable({
				data: data2,

			})
		},
		error: function(err) {
			console.log(err);
		}
	});
	fristLoad();

	$("#tab-first>li").eq(1).on("click", function() {

		$.ajax({
			type: "get",
			url: "http://192.168.59.3:8082/console/shopping/shop?shopType=2",
			contentType: "application/json",
			success: function(data) {
				console.log(data);

				$("#table-fundManage2").bootstrapTable({
					data: data,
					onSuccessLoad: function(data) {
						console.log(data);

					}
				})

			},
			error: function(err) {
				console.log(err);
			}
		});

	});
	$("#tab-first>li").eq(2).on("click", function() {
 console.log(window.cityid);
		$.ajax({
			type: "get",
			url: "http://192.168.59.3:8082/console/shopping/shop?shopType=3",
			contentType: "application/json",
			success: function(data) {
				console.log(data);

				$("#table-fundManage3").bootstrapTable({
					data: data,
					onSuccessLoad: function(data) {
						console.log(data);

					}
				})

			},
			error: function(err) {
				console.log(err);
			}
		});

	});

}
function resHandler(response) {
	console.log(response.data[0]);
	var needData = {
		rows: response.data[0],
		total: response.total
	};
	return needData;
}
// 获取所有的城市
function city() {
//	 获取所有的省份
	$.ajax({
		type: "get",
		url: "http://192.168.59.3:8082/console/basedata/area/provincelist",
		contentType: "application/json",
		success: function(data) {
		
			var data1 = JSON.parse(data).data;
		

			var sel1 = document.getElementsByClassName("prov")[0];
			var sel2 = document.querySelector(".city");
		
			for(var i = 0; i < data1.length; i++) {
				var optionObj = document.createElement('option');
				optionObj.innerHTML = data1[i].province;
				optionObj.value = data1[i].provinceid;
				sel1.appendChild(optionObj);
			}

			//          获取所有的市
			$.ajax({
				type: "get",
				url: "http://192.168.59.3:8082/console/basedata/area/citylist",
				contentType: "application/json",
				success: function(data) {
				
					var data2 = JSON.parse(data).data;
				
					sel1.onchange = function() {

						for(var i = 0; i < sel2.children.length; i++) {

							sel2.removeChild(sel2.children[i]);
							i--;
						}
						for(var k = 0; k < data2.length; k++) {
							if(sel1.value == data2[k].father) {
								var optionObj = document.createElement('option');
								optionObj.innerHTML = data2[k].city;
								optionObj.value = data2[k].cityid;
								sel2.appendChild(optionObj);
							}

						}
                           
                           
                           
					}
				sel2.onchange = function  () {
				
				    window.cityid = sel2.value;
				   
				}

				},
				error: function(err) {
					console.log(err);
				}
			});

		},
		error: function(err) {
			console.log(err);
		}
	});

}

function checkAllClick() {
	$("#table-fundManage1 [name=btSelectAll]").click()
}

function checkAll1Click() {
	$("#qhTable_2 [name=btSelectAll]").click();
}

function Dchoose() {
	$("#qhTable [name=btSelectItem]").change(function() {
		if($("#qhTable [name=btSelectItem]").length == $("#qhTable [name=btSelectItem]:checked").length) {
			$(".Dchoose").prop("checked", true);
		} else {
			$(".Dchoose").prop("checked", false);
		}
	})
}

function Dchoose1() {
	$("#qhTable_2 [name=btSelectItem]").change(function() {
		if($("#qhTable_2 [name=btSelectItem]").length == $("#qhTable_2 [name=btSelectItem]:checked").length) {
			$(".Dchoose1").prop("checked", true);
		} else {
			$(".Dchoose1").prop("checked", false);
		}
	})
}